def word_to_digit(word):
    words = {
        "zero": "0",
        "one": "1",
        "two": "2",
        "three": "3",
        "four": "4",
        "five": "5",
        "six": "6",
        "seven": "7",
        "eight": "8",
        "nine": "9"
    }
    return words.get(word)

def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

input_words = input().split()
if len(input_words) != 3:
    print("Wrong input")
else:
    number_str = "".join([word_to_digit(word) for word in input_words])
    if not number_str.isdigit() or len(number_str) != 3:
        print("Wrong input")
    else:
        number = int(number_str)
        lower_prime = None
        upper_prime = None
        i = 1
        while True:
            if number - i >= 0 and is_prime(number - i):
                lower_prime = number - i
                break
            if is_prime(number + i):
                upper_prime = number + i
                break
            i += 1
        
        if lower_prime is not None:
            print(lower_prime)
        elif upper_prime is not None:
            print(upper_prime)
